package org.lhq.utils;

import java.text.DecimalFormat;

/**
 * 字节数转文件大小工具类
 */
public class HexTransformationUtils {
    public static String formetFileSize(double fileSize) {
        DecimalFormat df = new DecimalFormat("#.00");
        String fileSizeString = "";
        if (fileSize < 1024) {
            fileSizeString = df.format(fileSize) + "B";
        } else if (fileSize < 1048576) {
            fileSizeString = df.format(fileSize / 1024) + "K";
        } else if (fileSize < 1073741824) {
            fileSizeString = df.format(fileSize / 1048576) + "M";
        } else {
            fileSizeString = df.format(fileSize / 1073741824) + "G";
        }
        return fileSizeString;
    }

}
